package org.song.util;


import org.song.util.snowFlake.SnowFlake;

import java.util.ArrayList;
import java.util.List;

public class SnowflakeUtil {

    private static SnowFlake snowflake = null;

    static {
        java.util.Random r=new java.util.Random();

        long datacenterId = r.nextInt(31);
        long workerId = System.currentTimeMillis()%31;
        snowflake = new SnowFlake(datacenterId, workerId);
    }

    public static String getNextId() {
        return String.valueOf(snowflake.nextId());
    }

    public static Long getNextLongId() {
        return snowflake.nextId();
    }

    public static List<String> getNextIds(int n) {

        List<String> keys = new ArrayList<>(n);

        for (int i = 0; i < n; i++) {
            keys.add(getNextId());
        }

        return keys;
    }
}
